package socketEnv;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;

/**
 * Created by hanyz on 2016/9/6.
 */
public class CrossProperties {
    private static HashMap<PropertiesEnum, Properties> propertiesEnumPropertiesHashMap = new HashMap<PropertiesEnum, Properties>();

    public enum PropertiesEnum {
        Core, Controls, DataView, NetServices, DataConversion,SpatialAnalyst
    }

    public static String getProperty(PropertiesEnum propertiesEnum, String key) {
        Properties propertyByEnum = getPropertyByEnum(propertiesEnum);
        if (propertyByEnum != null) {
            return propertyByEnum.getProperty(key);
        }
        return "";
    }


    private static Properties getPropertyByEnum(PropertiesEnum propertiesEnum) {
        Properties properties = propertiesEnumPropertiesHashMap.get(propertiesEnum);
        if (properties == null) {
            properties = new Properties();
            try {
                properties.load(new FileInputStream("./Properties/" + propertiesEnum + ".properties"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            propertiesEnumPropertiesHashMap.put(propertiesEnum, properties);
        }
        return properties;
    }

}
